package com.haipumi.servlets.backadmin;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.haipumi.beans.DataGrid;
import com.haipumi.beans.haipumi_skin;
import com.haipumi.beans.haipumi_user;
import com.haipumi.biz.IBackSkinBiz;
import com.haipumi.biz.impl.BackSkinBizImpl;
import com.haipumi.servlets.CommonServlet;
import com.haipumi.utils.CommonData;
import com.haipumi.utils.RequestUtil;

public class BackSkinServlet extends CommonServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 8647271778316072911L;

	IBackSkinBiz ibsb=new BackSkinBizImpl();
	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String op=null;
		op=request.getParameter("op");
		if("findallskin".equals(op)){
			findAllSkin(request,response);
		}else if("addskin".equals(op)){
			addskin(request,response);
		}else if("updateskin".equals(op)){
			updateskin(request,response);
		}
		
	}



	private void updateskin(HttpServletRequest request,
			HttpServletResponse response) {
		haipumi_skin newskin=null;
		try {
			haipumi_skin skin=RequestUtil.parseRequest(request, haipumi_skin.class);
			newskin=ibsb.updateSkin(skin);
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		super.outData(response, newskin);
	}



	private void addskin(HttpServletRequest request,
			HttpServletResponse response) {
		boolean isNewRecord=Boolean.parseBoolean(request.getParameter("isNewRecord"));
		haipumi_skin skin=null;
		haipumi_skin newskin=null;
		if(isNewRecord){
			//是添加操作
			try {
				skin=RequestUtil.parseRequest(request, haipumi_skin.class);
				newskin=ibsb.insertSkin(skin);
			} catch (NumberFormatException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IllegalArgumentException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}else{
			//是编辑操作
		}
		super.outData(response, newskin);
	}



	private void findAllSkin(HttpServletRequest request,
			HttpServletResponse response) {
//		List<haipumi_skin>skinlist=null;
//		skinlist=ibsb.findAllSkin();
//		DataGrid dg=new DataGrid();
//		dg.setRows(skinlist);
//		ServletContext application=this.getServletContext();   
//		application.setAttribute(CommonData.APPLICATIONSKINLIST, skinlist);
//		int total=0;
//		total=ibsb.countAllSkin();
//		dg.setTotal(total);
//		super.outData(response, dg);
	}

	
}
